<template>
	<view class="users">
		<block-bar :title="'我的'"></block-bar>
		<login-user-info :redRdius="redRdius"></login-user-info>
		<user-money :show="show"></user-money>
		<buy-sell-charge v-if="isLogin &&!reviewVersion"></buy-sell-charge>
		<block-img :data="exhibition"></block-img>
		<list-box></list-box>
	</view>
</template>

<script>
	import BlockBar from '@/components/BlockBar/BlockBar.vue'
	import LoginUserInfo from "./components/LoginUserInfo/LoginUserInfo.vue"
	import UserMoney from "./components/UserMoney/UserMoney.vue"
	import BuySellCharge from "./components/BuySellCharge/BuySellCharge.vue"
	import ListBox from "./components/ListBox/ListBox.vue"
	import BlockImg from '@/components/BlockImg/BlockImg.vue'
	import {mapState,mapActions} from "vuex"
	import {
		getNotices
	} from '@/api/public.js'
	import {
		advertisement
	} from '@/api/index.js'
	export default{
		components:{
			BlockBar,
			LoginUserInfo,
			UserMoney,
			BuySellCharge,
			ListBox,
			BlockImg
		},
		name:"users",
		data(){
			return{
				show:false,
				redRdius:false,
				redId:[],
				exhibition:{}
			}
		},
		onShow() {
			this.setUserInfo_action();
			this.show = uni.getStorageSync("isMoney") ? uni.getStorageSync("isMoney"): false;
			this.redRdius = uni.getStorageSync("redRdius") ? uni.getStorageSync("redRdius") : false;
			if(uni.getStorageSync("redId")){
				this.redId = JSON.parse(uni.getStorageSync("redId"))
			}
			this.getNoticeLists();
		},
		created() {
			advertisement({source:'my'}).then(res => {
				this.exhibition = res.data.length>0 ? res.data[0] : {};
			})
		},
		computed:{
			...mapState(["isLogin","reviewVersion"]),
		},
		methods: {
			...mapActions(['setUserInfo_action']),
			uniq(id){
				return this.redId.some((item)=>{
					return item == id
				})
			},
			async getNoticeLists() {
				let res = await getNotices({
					page: 1,
					size: 10
				});
				res.data.forEach((item)=>{
					let bool = this.uniq(item.id)
					if(bool){
						item.read = false
					}else{
						if(item.create_time < parseInt(Date.now()/1000)-86400*3){
							item.read = false
						}else{
							item.read = true
						}
					}
				})
				let arr = res.data.filter(item=>{return item.read})
				if(arr.length){
					uni.setStorageSync("redRdius",true)
					this.redRdius = true
				}else{
					uni.setStorageSync("redRdius",false)
					this.redRdius = false
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	// .users{
	// 	padding-top: var(--status-bar-height);
	// }
</style>
